package com.atserver.listener;

import com.atserver.windows.ScannerWindow;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

/**
 * @program: atserver
 * @Description: 鼠标移动获取屏幕坐标
 * @author: Mr.Cheng
 * @date: 2022/6/14 11:34 上午
 */
public class CoordinateMouseMove implements MouseMotionListener {

    private ScannerWindow scannerWindow;

    public CoordinateMouseMove() {
    }

    public CoordinateMouseMove(ScannerWindow scannerWindow) {
        this.scannerWindow = scannerWindow;
    }

    /**
     * Invoked when a mouse button is pressed on a component and then
     * dragged.  <code>MOUSE_DRAGGED</code> events will continue to be
     * delivered to the component where the drag originated until the
     * mouse button is released (regardless of whether the mouse position
     * is within the bounds of the component).
     * <p>
     * Due to platform-dependent Drag&amp;Drop implementations,
     * <code>MOUSE_DRAGGED</code> events may not be delivered during a native
     * Drag&amp;Drop operation.
     *
     * @param e
     */
    @Override
    public void mouseDragged(MouseEvent e) {

    }

    /**
     * Invoked when the mouse cursor has been moved onto a component
     * but no buttons have been pushed.
     *
     * @param e
     */
    @Override
    public void mouseMoved(MouseEvent e) {
        PointerInfo pinFo = MouseInfo.getPointerInfo();
        int mx = pinFo.getLocation().x;
        int my = pinFo.getLocation().y;

        scannerWindow.getXCoordinateTextField().setText(String.valueOf(mx));
        scannerWindow.getYCoordinateTextField().setText(String.valueOf(my));
    }
}
